<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="ZH_cn">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="pragma" content="no-cache">
	<title>阿来是</title>
	<link rel="stylesheet" href="/Public/home/css/index.css">
	<link rel="stylesheet" href="/Public/3rd/bootstrap/css/bootstrap.min.css">
	<script src="/Public/3rd/jquery/jquery.min.js"></script>


	<link rel="shortcut icon" href="/Public/images/favicon.ico"/>

</head>
<body>

	<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
	  <div class="container-fluid ">
		  <div class="container">
		  	<ul class="list-inline nav_ul">
		  		<li class="nav_li"><strong><a href="<?php echo U('Index/index');?>" class=" <?php if($action == 'home'): ?>default<?php endif; ?>" > 首页 </a></strong></li>
		  		<li class="nav_li"><strong><a href="<?php echo U('Chat/index');?>" class=" <?php if($action == 'chat'): ?>default<?php endif; ?>"> 聊天室 </a></strong></li>
		  		<li class="nav_li"><strong><a href=""  class=" <?php if($action == 'luntan'): ?>default<?php endif; ?>" >  论坛 </a></strong></li>
		  		<li class="nav_li"><strong><a href="<?php echo U('Usercenter/usercenter',array('action'=>'usercenter'));?>" class=" <?php if($action == 'usercenter'): ?>default<?php endif; ?>"   >  个人空间</a></strong></li>
	<!-- 	  		<li class="nav_li"><embed src="/Public/dnll.mp3" style="background:#ccc"   wmode="transparent"  autostart="true" loop="true"  ></embed></li> -->
		  		<!-- <li class="nav_li"><a href="">  保留 </a></li> -->
		  	</ul>
		  	<div class="user_manage">
				<?php if($_SESSION['user_name']== '' ): ?><a  data-toggle="modal" data-target="#loginModal">
  					登录
				</a>
				<?php else: ?>
				<span>欢迎 </span>
				<span id="username"><?php echo (session('user_name')); ?></span>
                    <a href="javascript:void(0)" onclick="logout()">注销</a><?php endif; ?>
		  	</div>

		  </div>
	  </div>
	</nav>
<!-- loading层 -->
<div id="loadingLayout" class="hide" style="position:fixed;top:51px;left:80px;
    right: 0px;
    bottom: 0px;
    display: flex;
    opacity: 0.5;
    background: rgb(222, 225, 226);
    z-index: 10000;
    text-align: center;
    -webkit-box-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    align-items: center;">
	<img src='/Public/home/img/loading.gif' alt=''>
</div>


 <script>
 var Think = {
     "APP": '/index.php',
     "URL": '/index.php/Usercenter',
     "ROOT": '',
     "PUBLIC": '/Public'
 };</script>


<style>
.cbp-vimenu{
	top: 50px; 
}	

</style>
		<link rel="stylesheet" type="text/css" href="/Public/home/css/default.css" />
		<link rel="stylesheet" type="text/css" href="/Public/home/css/component.css" />
		<script src="/Public/3rd/jquery/jquery.min.js"></script>
		<script src="/Public/home/js/modernizr.custom.js"></script>


			<link rel="stylesheet" href="/Public/icon/iconfont.css">
<style>
.menu_li {
    height: 80px;
    line-height: 80px;
    font-size: 16px;
    width: 80px;
    text-align: center;
    cursor: pointer;
}

.menu_li:hover {
    background: #cde5f7
}

.menu_li i {
    color: #666;
    font-size: 40px
}

.menu_li i:hover {
    color: #fff;
    font-weight: bold
}

.usermenu_menu {
    padding: 0;
    background: #ddedfa;
    /*padding:6px;*/
}

.active {
    background-color: #47a3da;
}
</style>
<div id="sidebar" style="position: fixed;width:80px;top:50px;">
    <ul class="usermenu_menu">
        <li class="menu_li" page_code=""><i class="iconfont icon-xing "></i></li>
        <li class="menu_li" page_code="userlist"><i class="iconfont icon-ren"></i></li>
        <li class="menu_li" page_code="img_manage"><i class="iconfont icon-image"></i></li>
        <li class="menu_li" page_code="photo"><i class="iconfont icon-xiangce"></i></li>
        <li class="menu_li" page_code="setup"><i class="iconfont icon-peizhi"></i></li>
    </ul>
</div>
<div id="page_code-content" class="page_code-content row" style="margin:0 0 0 80px">
</div>

<script src="/Public/home/js/app.js"></script>
<script>
var Think = {
    "APP": '/index.php',
    "URL": '/index.php/Usercenter',
    "ROOT": '',
    "PUBLIC": '/Public'
};
$(function() {

    var url_code = localStorage.getItem("user_url");

    if (url_code != "") {

        $(".usermenu_menu>li").each(function(index) {

            var type = $(this).attr('page_code');
            if (type == url_code) {
                $(this).addClass('active');
                repeat_list(url_code);
            }
        });

    }
})

// 用户中心菜单栏js
$(".usermenu_menu>li").on("click", function() {

    var gObj = $(this);
    $(".usermenu_menu>li").removeClass('active');
    gObj.addClass('active');
    page_code = gObj.attr("page_code");

    repeat_list(page_code);
});
var wh = $(window).height();
$(".usermenu_menu").css("height", wh - 50);

var wh = $(window).height();
$(".usermenu_menu").css("height", wh - 50);





function repeat_list(page_code) {
    var url = "<?php echo U('Usercenter/index',array('code'=>'page_code'));?>";
    url = url.replace('page_code', page_code);
    var url = "<?php echo U('Usercenter/index',array('code'=>'page'));?>";
    url = url.replace('page', page_code);


    loadHtmlData("#page_code-content", url)
    // $.ajax({
    //     // url:"<?php echo U(Usercenter/index,array('code'=>'userlist'));?>",
    //     // url:Think.APP+"/Usercenter/index/code/"+page+"<?php echo (C("URL_HTML_SUFFIX")); ?>",
    //     url: url,
    //     type: "get",
    //     data: {
    //         page_codesize: 8
    //     },
    //     success: function(data) {
    //         // localStorage.removeItem("user_url");

    //         // $("#page_code-content").
    //         $("#page_code-content").html(data);
    //     },
    //     error: function() {
    //         console.log("网络错误")
    //             /* Act on the event */
    //     }
    // })

}
</script>


<footer class="container"> 
	　　<p class="foot_text">© 阿来 版权所有<br /> 个人社交管理空间</p>
	　　 
	</footer> 
		
	<script src="/Public/3rd/bootstrap/js/bootstrap.min.js"></script>
	<script src="/Public/3rd/jquery/jquery.validate.min.js"></script>
	<script src="/Public/3rd/jquery/messages_zh.js"></script>
	<script src="/Public/home/js/app.js"></script>
	<div class="modal fade" id="loginModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-body login_content">
	      <!-- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> -->
		      <form id="loginForm" action="">
			      <a title="关闭" href="#" class="login_dialog_close" data-dismiss="modal">×</a>
			        <h3 class="login_title">欢迎来到空间，请登录</h3>
			        <div class="user_input mtop-12" >
			        	<input type="text" name="username" id="username" placeholder="用户名">
			        </div>
			        <div class="pwd_input mtop-12">
			        	<input  id="password" type="password" name="password" placeholder="密码">
			        </div>
			        <button class="btn submit mtop-12"  style="background: #DE533C">登录</button>
			        <p style="position: absolute;bottom: 0;right: 60px;font-size: 12px;">新用户请先<a href="/index.php/Public/register.html">注册</a></p>
		      </form>
	      </div>
	    </div>
	  </div>
	</div>
	<div id="codeContainer" style="position: fixed;top:0;left:0;right:0;bottom:0;display: -webkit-box;-webkit-box-pack: center; -webkit-box-align: center;z-index:1080" class="hide">
		<div id="codeBox" style="width:300px;height:200px;background: #fff">
			<div class="title" style="height: 35px;line-height: 35px;background:#6699FF;position: relative;">
				<span style="color:#fff;padding-left: 4px;"><strong>请输入验证码</strong></span>
				<a id="codeClose" style="color:#ccc;font-size: 22px;position: absolute;top:-2px;right:6px;cursor: pointer">x</a>
			</div>
			<div class="mtop-12">
				<span style="padding-left: 22px;">验证码：</span>
				<input id="inputCode" type="text">
				<p id="codeTip" class="hide">验证码错误</p>
			</div>
			
			<img id="getcode_math" class="" src="<?php echo u('Public/get_verification_code');?>" title="看不清，点击换一张" style="    cursor: pointer;
    height: 40px;
    width: 140px;
    margin-top: 12px;
    margin: 12px 88px;
    display: block;"  onerror="" alt="..." />
    	<hr>
    	<button id="checkCode" style="    margin: 0 auto;
    display: block;
    width: 80px;
    height: 35px;
    border-radius: 3px;
    color: #fff;
    border: none;
    background: darkseagreen;" >完成</button>
		</div>
		
	</div>

	<script>
		$(function(){

 			var domObj = $("#imgContainer");
 			var imgNum = Math.floor(Math.random()*10+1); //1-10    
 			domObj.addClass(`content_bg_${imgNum}`);
			var validateOptions = {
	                rules: {
	                    username:{
	                        required: true
	                    },			                  
	                    password:{
	                    	required:true
	                    }
	                },
	                messages: {
	                    username:{
	                    	required:"请输入用户昵称",
	                    },
	                    password:{
	                    	required:"请输入密码"
	                    }             
	                },
	                errorPlacement: function(error, element) {  
	                	debugger;
	                	// element.val(error.text());
	                	element.attr("placeholder",error.text());
    					// error.appendTo(element.parent());  
					}
	            };
	        var validator = $("#loginForm").validate(validateOptions);

	        
 			$(".submit").bind("click", function(e){
 				e.preventDefault() ;
 				debugger;
 				if(validator.form()){
 					$("#codeContainer").removeClass("hide");
 					// $("#codeTip").addClass('hide');
 					$("#codeClose").unbind("click").bind("click", function(){
 						$("#codeContainer").addClass('hide');
 					});
 					$("#getcode_math").click(function(){
 					    $(this).attr("src","<?php echo u('Public/get_verification_code');?>?" + Math.random());
 					 });
 					$("#getcode_math").trigger("click");
 					$("#inputCode").val("");
 					$("#checkCode").unbind("click").bind("click", function(e){
 						e.preventDefault();
 						$("#inputCode").focus(function(){ 
				        	$(this).attr("placeholder","");
				        });

 						if($("#inputCode").val()){
 							$.ajax({
 								url:Think.APP+"/Public/check_code",
 								type:"post",
 								dataType:"json",
 								data:{"code":$("#inputCode").val()},
 								success:function(data){
 									debugger;
 									if (data.state==="success") {
 										userLogin();
 									}else{		
 										$("#getcode_math").trigger("click");
										$("#inputCode").val("");
	                					$("#inputCode").attr("placeholder","验证码错误");
 									}
 								},
 								error:function(){
 									console.log("验证码验证失败");
 									$("#getcode_math").val("").trigger("click");

 								}
 							})
 						}else{
 							$("#inputCode").attr("placeholder","请输入验证码")
 						}
 					})		
 				}
 				
 			})
 			function userLogin(){
 				var name = $.trim($("#username").val());
 				var pwd = $.trim($("#password").val());
 				if(name && pwd){
 					$("#codeContainer").addClass('hide');
					$.ajax({
	 					url:Think.APP+"/Public/check_login",
	 					type:"post",
	 					dataType:"json",
	 					data:{
	 						"username":name,
	 						"password":pwd
	 					},
	 					success:function(data){
	 						if(data.state==="success"){
	 							alert("登录成功");
	 							history.go(0)
//	 							console.log("登录成功");
	 						}else{
	 							alert("用户名或密码错误");	 						
	 						}
	 					},
	 					error:function(){
	 						alert("接口不存在")
	 					} 						
					})
				}
 			}
		})
	</script>